home *** CD-ROM | disk | FTP | other *** search
/ Cracking 2 / Cracking II..iso / Texty / crackme / CRUEME.BAK < prev    next >
Encoding:
Text File  |  1998-10-03  |  13.1 KB  |  511 lines

  1. ;-----------------------------------------------------------------------------------
  2. ; Title:              : CrueMe v1.0
  3. ; Author              : Cruehead
  4. ; Creation date       : 98-06-02
  5. ; Source release date : 98-10-10
  6. ;
  7. ; Description:
  8. ; This is the source code for yet another "CrackMe" program. This one
  9. ; has proven to be fairly hard to beat as I have only recieved two
  10. ; solutions. It features some polymorphic code to hide the real
  11. ; encryption and check routine. As soon as the real check has been executed
  12. ; the code will be overwritten with useless code, and a fake
  13. ; encryption/check routine will be executed. Every time the "Check It!"
  14. ; button is pressed the real encryption/check routine is beeing written
  15. ; to the correct place again. Before the real encryption/check routine is executed
  16. ; the string is fetched through the GetText message beeing sent.
  17. ; A breakpoint detection is made on the "GetDlgItemTextA" function as this
  18. ; is the routine that is used to fetch the string and then execute the fake test.
  19. ; All of this just to confuse the cracker into thinking he's on the right path
  20. ; when seeing the "No breakpoint..." message. Also the file called "CRUEME.DAT" has
  21. ; nothing to do whatsoever with the real check - it's only used as a red herring.
  22. ; Knowing this one can easily figure out that the "FileMon" detection is also only
  23. ; used as a red herring to distract the user from the real interesting piece of
  24. ; the code.
  25. ; Another thing is that all the functions used in the program are stored in a
  26. ; separate place thus making it a lookup table. This is only to confuse
  27. ; dead-listing crackers (and perhaps to cause some headaches).
  28. ; Conclusion: Alot of things to draw the cracker's attention to other useless
  29. ; pieces of the code. Also the ability to hide the real psw checking routine so the
  30. ; cracker wont see anything suspicious when browsing through the program using softice.
  31. ;
  32. ; I wont comment much of the code, and it might be a bit hard to follow everything
  33. ; but the program works as I described above and that is - if you ask me - the really
  34. ; interesting thing to know.
  35. ;
  36. ;
  37. ;
  38. ; Oh yeah! Perhaps you'd be interested to know that the password I choosed was
  39. ; "Cracking4U". Alot of other passwords will pass as well though.
  40. ;-----------------------------------------------------------------------------------
  41.  
  42. .386
  43. locals
  44. jumps
  45. .model flat,STDCALL
  46.  
  47. ;----------------------------------------------------------
  48. ;Structure, EQU, Includefiles declaration
  49. ;----------------------------------------------------------
  50.  
  51. include win32.inc           ; some 32-bit constants and structures
  52. L equ <LARGE>
  53.  
  54. IDD_STAT         EQU 1010
  55. IDD_CLOSE         EQU 1004
  56. IDD_GO             EQU 1003
  57. IDD_EDIT1         EQU 1002
  58. IDI_ICON1         EQU 100
  59.  
  60. TRUE             EQU 1
  61. FALSE              EQU 0
  62. NULL             EQU 0
  63.  
  64. ;----------------------------------
  65. ; Our Variables
  66. ;----------------------------------
  67.  
  68. .data
  69.  
  70. szTitleName      db '',0
  71. szClassName      db 'ASMCLASS32',0
  72. lppaint          PAINTSTRUCT <?>
  73. msg              MSGSTRUCT   <?>
  74. wc               WNDCLASS    <?>
  75. tm                 TEXTMETRIC  <?>
  76. RC                 RECT         <?>
  77. Systime             SYSTEMTIME  <?>
  78.  
  79. dlg_start        db 'DLG_START',0
  80. Buffert             db 7,41,25,22,37,6,1,12,35,24,11,8,23,14,5,42,33,38,27,3,21,4,39,10,20,26,19,28,32,40,31,29,34,9,17,36,15,18,13,30,2,16
  81.  
  82. psw                 db 14 dup (0)
  83. fakebuff         db 8 dup (0)
  84. loopindex         db 0ffh
  85.  
  86. FileFakePsw         db 0ffh,077h,088h,066h,099h,055h,0aah,044h,0bbh,033h,0cch,022h,0ddh,011h,0eeh
  87.  
  88. Flagst             dd 0c0h            ; Open with these flags! (RWE)
  89. FileMon             db 05dh,0a5h,0b9h,0e4h,0d4h,080h,019h,0a5h,0b1h,095h,080h,035h,0bdh,0b9h,0a5h,0d1h,0bdh,0c9h,0
  90. ProcID             dd 0
  91. handle             dd 0
  92.  
  93. WhyNot1             dd 015263748h
  94. WhyNot2             dd 0596a7b8ch
  95. NoNeed1             dd 0
  96. NoNeed2             dd 0
  97. length             dd 0
  98.  
  99. Filename         db 'CRUEME.DAT',0
  100. filehandle         dd 0
  101. readbuffer         db 15 dup (0)
  102. somanyread         dd 0
  103.  
  104. NotUsedYet1         dd 0
  105. NotUsedYet2         dd 0
  106.  
  107. FileHeader         db "This is the end - My only friend the end!",0
  108. FileMissing         db 'AAARGH! Where is my CRUEME.DAT file???',13
  109.                  db '    I cant go on without my beloved file!',0
  110.  
  111. tempflag         db 0
  112. statwait         db 'Status: Waiting for input',0
  113. statyes             db 'Correct password - Good work!',0
  114. statno             db 'False password - Try again',0
  115. statyescopy         db 30 dup (0)
  116.  
  117. siceHeader         db 'Breakpoints - just say no!',0
  118. nosice             db "So - You're trying to put a breakpoint on GetDlgItemTextA, eh?",13
  119.                  db "You know - I cant allow you to do that... that would make",13
  120.                  db "things easy for you, so...sorry mate - This has to end right now!",0
  121.  
  122. XorSeed             db 0
  123. chooseofs         dd 0
  124. para1              dd 0
  125. para2              dd 0
  126. return             dd 0
  127.  
  128. oldprot             dd 0
  129. paddress          dd 0400000h
  130. pseudo             dd 0
  131. patchhere         dd 0802448h                        ; / 2 = 0401224h
  132. regsize              dd 4096
  133. byteswritten     dd 0
  134.  
  135. RealRoutine         db 052h,06ah,00eh,06ah,00dh,068h,0eah,003h,000h,000h,0ffh,075h,008h,0b0h,025h
  136.                  db 0ffh,015h,064h,023h,040h,000h,0e8h,035h,009h,000h,000h,050h,0bfh,001h,000h
  137.                  db 000h,000h,0e8h,0fdh,008h,000h,000h
  138.  
  139. FakeRoutine         db 0b1h,096h,055h,08bh,0ech,051h,083h,0ech,03ch,066h,0ffh,075h,008h,0ffh,075h,00ch,098h,0b1h,095h,08bh
  140.                  db 0ech,08bh,075h,00ch,00bh,0f6h,08dh,07dh,0b8h,057h,00bh,0ffh,0c1h,0e0h,004h,003h,0c2h
  141. hInst             dd 0
  142. hMenu             dd 0
  143. hDlg              dd 0
  144.  
  145. ;-----------------------------------
  146. ; Startup
  147. ;-----------------------------------
  148.  
  149. .code
  150.  
  151. ;---------------------------------------------------------
  152. ; This is where control is received from the loader.
  153. ;---------------------------------------------------------
  154.  
  155. start:
  156.         mov        chooseofs,offset choose
  157.  
  158.         push    offset Systime
  159.         call    GetLocalTime
  160.         lea        ebx,[ebx*4]
  161.         shr        patchhere,1
  162.         mov        ax, Systime.wMilliseconds        ;Get Milliseconds in AX
  163.         mov        XorSeed,al                        ;AL = our XorSeed
  164.         call    XorBuffer
  165.  
  166.         add        eax,5
  167.         lea        eax,[eax*4]
  168.         add        eax,5
  169.  
  170.         call    FixShutDown
  171.  
  172.         push    L 0
  173.         push    L 080h
  174.         push     L 3
  175.         push    L 0
  176.         push    L 0
  177.         push    0C0000000h
  178.         push    offset Filename
  179.         mov        al,31
  180.         call    [chooseofs]                        ;CreateFileA = 8
  181.         cmp        eax,-1
  182.         jnz        Goon
  183.  
  184.         push    L MB_ICONEXCLAMATION
  185.         push    offset FileHeader
  186.         push    offset FileMissing
  187.         push    0
  188.         mov        al,26
  189.         call    [chooseofs]                        ;MessageBoxA = 33
  190.  
  191.         push    [msg.msWPARAM]
  192.         mov        al,10
  193.         call    [chooseofs]                        ;ExitProcess = 34
  194.  
  195.         Goon:
  196.         mov        filehandle,eax
  197.         mov     eax,15
  198.         mov     ebx,offset readbuffer
  199.         push     L 0
  200.         push     offset somanyread
  201.         push     eax
  202.         push     ebx
  203.         push     [filehandle]
  204.         mov        al,29
  205.         call    [chooseofs]                        ;ReadFile = 14
  206.  
  207.         push    [filehandle]
  208.         mov        al,42
  209.         call    [chooseofs]                        ;CloseHandle = 7
  210.  
  211.         push    L 0
  212.         mov        al,19
  213.         call    [chooseofs]                          ;GetModuleHandle = 10
  214.         mov        [hInst], eax
  215.  
  216.         push    L 0
  217.         push    offset szClassName
  218.         mov        al,39
  219.         call    [chooseofs]                          ;FindWindow = 22
  220.         or      eax,eax                 
  221.         jz      reg_class                       ;More programs than one?
  222.         ret                                     ;No, only one open at time
  223.  
  224. reg_class:
  225.  
  226.         mov     [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
  227.         mov     [wc.clsLpfnWndProc], offset WndProc
  228.         mov     [wc.clsCbClsExtra], 0
  229.         mov     [wc.clsCbWndExtra], 0
  230.  
  231.         mov     eax, [hInst]
  232.         mov     [wc.clsHInstance], eax
  233.  
  234.         push    IDI_ICON1
  235.         push    eax
  236.         mov        al,5
  237.         call    [chooseofs]                        ;LoadIcon = 18
  238.         mov     [wc.clsHIcon], eax
  239.  
  240.         push    L IDC_ARROW             
  241.         push    L 0
  242.         mov        al,14
  243.         call    [chooseofs]                        ;LoadCursor = 32
  244.         mov     [wc.clsHCursor], eax
  245.  
  246.         push    L 0                     
  247.         push    offset Main_DlgProc     
  248.         push    L 0
  249.         push    offset dlg_start                ;Startup dlg resource (main resource)
  250.         push    [hInst]
  251.         mov        al,18
  252.         call    [chooseofs]                        ;DialogBoxParamA = 20
  253.         jmp     finish                          ;Back main window
  254.  
  255. msg_loop:
  256.         push    L 0
  257.         push    L 0
  258.         push    L 0
  259.         push    offset msg
  260.         mov        al,36
  261.         call    [chooseofs]                        ;GetMessage = 1
  262.         call    choose
  263.  
  264.         cmp     ax, 0
  265.         je      end_loop
  266.  
  267.         push    offset msg
  268.         mov        al,9
  269.         call    [chooseofs]                        ;TranslateMessage = 9
  270.  
  271.         push    offset msg
  272.         mov        al,6
  273.         call    [chooseofs]                        ;DispatchMessage = 15
  274.  
  275.         jmp     msg_loop
  276.  
  277. end_loop:
  278.         push    [msg.msWPARAM]
  279.         mov        al,10
  280.         call    [chooseofs]                        ;ExitProcess = 34
  281.  
  282. ;----------------------------------------------------------------------------
  283. ; WARNING: Win32 requires that EBX, EDI, and ESI be preserved!  
  284. ;
  285. ; In this part we will put the events we want to respond on.
  286. ; Key, MouseButtons, Resize, Menu, Commands.... (look at the win32.inc)
  287. ; You can leave the above without changes a modify the next part only
  288. ;----------------------------------------------------------------------------
  289.  
  290. WndProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  291.         push    esi
  292.         push    edi
  293.         push    ebx
  294.         jmp     defwndproc
  295. defwndproc:
  296.         push    [lparam]
  297.         push    [wparam]
  298.         push    [wmsg]
  299.         push    [hwnd]
  300.         call    DefWindowProc
  301.         jmp     finish
  302.  
  303. finish:
  304.         pop     ebx                             ;Remember we must restore these registers
  305.         pop     edi                             ;Because the OS need them
  306.         pop     esi
  307.         ret
  308.  
  309. WndProc          endp
  310.  
  311. public WndProc
  312.  
  313.  
  314. ;----------------------
  315. ;Start Dialog
  316. ;----------------------
  317.  
  318. Main_DlgProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  319.  
  320.         push    ebx
  321.         push    esi
  322.         push    edi
  323.  
  324.         cmp     [wmsg],WM_COMMAND                ;Respond to buttons
  325.         je      main_command
  326.         cmp     [wmsg], WM_CLOSE                ;Respond to if we want to shut it down
  327.         je      main_dlgdestroy
  328.                        
  329.         mov     eax,FALSE
  330.  
  331. main_finish:
  332.         pop     edi
  333.         pop     esi
  334.         pop     ebx
  335.         ret
  336.  
  337. updatestat:
  338.         Call     PolySetup
  339.  
  340.         push    offset statwait
  341.         push    IDD_STAT
  342.         push    [hwnd]
  343.         mov        al,21
  344.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  345.  
  346.         mov        tempflag,1        
  347.         mov        eax,TRUE
  348.         jmp        main_finish
  349.         
  350. ;---------------------------------
  351. ;HERE IS WHERE THE FUN PART BEGINS
  352. ;---------------------------------
  353.  
  354. main_go:                        
  355.  
  356.         mov        edx,offset psw
  357.         lea        ebx,[eax*4]
  358.         add        ebx,5
  359.         add        ebx,edx
  360.  
  361.         push    edx
  362.         push    L 14
  363.         push    L WM_GETTEXT
  364.         push    L IDD_EDIT1
  365.         push    [hwnd]
  366.         mov        al,37
  367.         call    [chooseofs]                        ;SendDlgItemMessageA = 6
  368.         call    RealProt
  369.         push    eax
  370.  
  371.         mov        edi,1                            ;Edi=1 --> Write FakeCode
  372.         call    PolyWrite
  373.  
  374.         mov        ecx,8
  375.         lea        edi,readbuffer
  376.         lea        esi,FileFakePsw        
  377.         fakefake:
  378.         mov        al, byte ptr [edi]
  379.         mov        bl, byte ptr [esi]
  380.         xor        al,bl
  381.         rol        al,1
  382.         mov        byte ptr [esi],al
  383.         inc        edi
  384.         inc        esi
  385.         loop    fakefake
  386.  
  387.  
  388.         pop        eax
  389.         test    eax,eax
  390.         je        Noneedforthis
  391.  
  392.         lea        edi,GetDlgItemTextA
  393.         push    10
  394.         push    offset psw        
  395.         push    IDD_EDIT1
  396.         push    [hwnd]
  397.  
  398.         push    ds
  399.         push    cs
  400.         pop        ds
  401.         mov        edi,[edi+2]                        ;Get DLL function jmp address
  402.         mov        edi,[edi]                        ;Get DLL function real address
  403.         mov        eax,[edi]                        ;Get first bytes of DLL function
  404.         pop        ds
  405.         and     eax,0FFh                        ;Save only the first byte
  406.         cmp        eax,0CCh                        ;It this function BPX'ed?
  407.         jne        NoBPX
  408.  
  409.         push    L MB_ICONEXCLAMATION
  410.         push    offset siceHeader
  411.         push    offset nosice
  412.         push    0
  413.         mov        al,26
  414.         call    [chooseofs]                        ;MessageBoxA = 33
  415.  
  416.         push    [msg.msWPARAM]
  417.         mov        al,10
  418.         call    [chooseofs]                        ;ExitProcess = 34
  419.  
  420.         NoBPX:
  421.         call    edi
  422.  
  423.         call    fakeprot
  424.         test    eax,eax
  425.         je        fakenotvalid
  426.  
  427.         push    offset statyes
  428.         push    IDD_STAT+1
  429.         push    [hwnd]
  430.         mov        al,21
  431.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  432.  
  433.         fakenotvalid:
  434.         push    offset statno
  435.         push    IDD_STAT
  436.         push    [hwnd]
  437.         mov        al,21
  438.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  439.         
  440.         Noneedforthis:
  441.         xor        edi,edi
  442.         call    PolyWrite                        ;Edi=0 --> Write RealProtScheme
  443.         mov        eax,TRUE
  444.         jmp        main_finish
  445.  
  446.  
  447. main_command:
  448.         cmp        tempflag,0
  449.         je        updatestat
  450.         cmp        [wparam],IDD_GO                    ;User clicked on "check" button?
  451.         je        main_go
  452.         cmp     [wparam],IDD_CLOSE
  453.         jne     main_nothing
  454.  
  455. main_dlgdestroy:
  456.         push    L 0             
  457.         push    [hwnd]
  458.         mov        al,3
  459.         call    [chooseofs]                         ;CloseDialog = 30
  460.  
  461.         mov     eax,TRUE        
  462.         jmp     main_finish
  463.  
  464. main_nothing:
  465.  
  466.         push    offset FileMon
  467.         push     L 0
  468.         mov        al,39
  469.         call    [chooseofs]                          ;FindWindow = 22
  470.         test    eax,eax        
  471.         jz        noclose
  472.  
  473.         push     offset ProcID
  474.         push     eax            
  475.         mov        al,30
  476.         call    [chooseofs]                        ;GetWindowThreadProcessId = 23
  477.         test     eax,eax
  478.         jz       noclose
  479.  
  480.         push     [ProcID]                        ;Owner process ID
  481.         push     L 0
  482.         push     offset Flagst                    ;Flags = Read/Write
  483.         mov        al,8
  484.         call    [chooseofs]                        ;OpenProcess = 17
  485.         test     eax,eax
  486.         jz         noclose
  487.         mov        handle,eax
  488.  
  489.         push    offset ProcID
  490.         push    eax
  491.         mov        al,32
  492.         call    [chooseofs]                        ;GetExitCodeProcess = 11
  493.         test    eax,eax
  494.         jz        noclose
  495.             
  496.         push    [ProcID]
  497.         push    [handle]
  498.         mov        al,13
  499.         call    [chooseofs]                        ;TerminateProcess = 40
  500.  
  501. noclose:
  502.  
  503.         mov     eax,FALSE
  504.         jmp     main_finish
  505.  
  506. Main_DlgProc    endp
  507. public Main_DlgProc
  508.        include morefunc.asm
  509.  
  510. end start
  511.